package com.lee.lease.web.app.custom;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration("Knife4jConfiguration2")
public class Knife4jConfiguration {

    @Bean
    public OpenAPI customOpenAPI() {

        return new OpenAPI()
                .info(new Info()
                        .title("App管理系统API")
                        .version("1.0")
                        .description("后台管理系统API")
                        .termsOfService("http://doc.xiaominfo.com")
                        .license(new License().name("Apache 2.0").url("http://doc.xiaominfo.com")))
                .components(new Components().addSecuritySchemes("access_token", new SecurityScheme().type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER).name("access_token")));
    }

    @Bean
    public GroupedOpenApi LoginAPI() {

        return GroupedOpenApi.builder().group("登录信息").
                addOperationCustomizer(
                        (operation, handlerMethod) -> operation.addSecurityItem(new SecurityRequirement()
                                .addList("access_token"))).
                pathsToMatch(
                        "/app/login/**","/app/info"
                ).
                build();
    }
    @Bean
    public GroupedOpenApi LoginAPI2() {

        return GroupedOpenApi.builder().group("个人信息").
                addOperationCustomizer((operation, handlerMethod) -> operation.addSecurityItem(new SecurityRequirement().addList("access_token"))).
                pathsToMatch(
                        "/app/appointment/**"
                ).
                build();
    }
    @Bean
    public GroupedOpenApi LoginAPI3() {

        return GroupedOpenApi.builder().group("租约管理").
                addOperationCustomizer((operation, handlerMethod) -> operation.addSecurityItem(new SecurityRequirement().addList("access_token"))).
                pathsToMatch(
                        "/app/agreement/**",
                        "/app/history/**"
                ).
                build();
    }
    @Bean
    public GroupedOpenApi LoginAPI4() {

        return GroupedOpenApi.builder().group("找房信息").
                addOperationCustomizer((operation, handlerMethod) -> operation.addSecurityItem(new SecurityRequirement().addList("access_token"))).
                pathsToMatch(
                        "/app/term/**",
                        "/app/apartment/**",
                        "/app/region/province/**",
                        "/app/payment/**",
                        "/app/room/**"

                ).
                build();
    }



}